package club.hicode.daydayup.file;

import com.google.common.io.Files;
import org.junit.Test;

import java.io.File;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

/**
 * 清空更新错误的
 *
 * @author Liu Chunfu
 * @date 2018-07-16 下午4:16
 **/
public class CleanNexusLastUpdated {


    private static final String LOCAL_ROOT = "/Users/liuchunfu/develop/repository/";


    @Test
    public void cleanLocal() {
        Iterable<File> files = Files.fileTraverser().depthFirstPostOrder(new File(LOCAL_ROOT));
        //将iterator转换为stream
        List<File> lastUpdatedList = StreamSupport.stream(files.spliterator(), false)
                .filter(file -> file.getName().endsWith("lastUpdated")).collect(Collectors.toList());

        lastUpdatedList.forEach(file -> {
            //System.out.println(file.getName());
            boolean result = file.delete();
            System.out.println("删除结果为:" + result + " 目录为:" + file.getName());
        });
    }

    private static final String NEXUS_ROOT = "/Users/liuchunfu/develop/nexus/sonatype-work/nexus/storage";


    @Test
    public void cleanNexus() {
        Iterable<File> files = Files.fileTraverser().depthFirstPostOrder(new File(LOCAL_ROOT));
        //将iterator转换为stream
        List<File> lastUpdatedList = StreamSupport.stream(files.spliterator(), false)
                .filter(file -> file.getName().endsWith("lastUpdated")).collect(Collectors.toList());

        lastUpdatedList.forEach(file -> {
            //System.out.println(file.getName());
            boolean result = file.delete();
//			boolean result = true;
            System.out.println("删除结果为:" + result + " 目录为:" + file.getName());
        });
    }
}
